package com.shop.factory;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ObjectFactory {
	private static Properties pro = new Properties();
	static{
		InputStream is =
				ObjectFactory.class.getResourceAsStream("bean.properties");

		try {
            //InputStream is = new FileInputStream("/shopping/bean.properties");
			pro.load(is);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}



	public static Object getInstance(String key){
		String className = pro.getProperty(key);
		if(className != null){
			try {
				return Class.forName(className).newInstance();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}
}
